package ui.panel.setup;

import cerebrum.cache.MacDateTaskStatusCache;
import cerebrum.cache.ImagesDataLoaderCache;
import cerebrum.common.ConfigPropertiesUtil;
import cerebrum.controller.wallpaper.WallpaperCerebrum;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import ui.factory.SingletonFactory;
import ui.panel.DownloadLogStage;
import ui.panel.setup.subsidiary.SetUpChoiceStage;
import ui.task.MacTimeTask;
import ui.util.Window;

import java.io.IOException;
import java.util.Collections;
import java.util.Timer;

public class WallpaperTypeChoiceStage extends Window {
    private static final String HEART_MOVED_COLOR = "#f1441d;";
    private static final String HEART_EXIT_COLOR = "#ee2746;";

    private static WallpaperTypeChoiceStage instance = null;
    //father pane
    private Pane pane = new Pane();
    private Pane topMenu = new Pane();
    private Pane brokenHeart = new Pane();
    private HBox bottomMenu = new HBox();
    private Pane bottomMenuBackground = new Pane();

    private Pane setUpChoice;
    //修复心的时间线
    Timeline repairHeartTime = new Timeline();

    //调用单例工厂
    public static WallpaperTypeChoiceStage getInstance() {
        if (instance == null) {
            instance = SingletonFactory.getWeakInstace(WallpaperTypeChoiceStage.class);
        }
        return instance;
    }

    public WallpaperTypeChoiceStage(){
        pane.setId("root");
        //Set Mouse Cursor Style
        setCursor(pane);
        setIcon();
        pane.setStyle("-fx-background-color:TRANSPARENT;");
        macBokBackground();
        welComeLogoAnimation();
        //顶部菜单
        topMenu(pane);


        Scene scene = new Scene(pane, 1500, 830);
        scene.getStylesheets().add("/fxml/css/transparent-text-area.css");
        initStyle(StageStyle.TRANSPARENT);
        scene.setFill(Color.TRANSPARENT);
        setScene(scene);
        setTitle("IceoLogy壁纸");
    }
    private void major(){
        //MacBok and Mac Wallpaper
        macWallpaper(pane);
        //下方菜单
        bottomMenu(pane);
        topMenu.setVisible(true);
        //设置不在隐藏
       topMenu.setManaged(true);
        //调整控件顺序，避免遮挡
        ObservableList<Node> paneNode = FXCollections.observableArrayList(pane.getChildren());
        Node node = paneNode.get(1);
        paneNode.add(node);
        paneNode.remove(1);
        pane.getChildren().setAll(paneNode);
    }

    //mac bok 背景
    private void macBokBackground(){
        //mac边框
        Image macImage = new Image("/fxml/css/images/mac/macbook_0.png");
        ImageView mac = new ImageView(macImage);
        mac.setFitWidth(1500);
        mac.setFitHeight(830);
        pane.getChildren().addAll(mac);
    }

    private void welComeLogoAnimation() {
        Pane animation = new Pane();
        animation.setPrefHeight(677);
        animation.setPrefWidth(1145);
        animation.setLayoutX(180);
        animation.setLayoutY(50);
        animation.setStyle("-fx-background-color:#F8F8FF;");
//        //mac的壁纸
        Image logoImage = new Image("/fxml/css/images/66666.gif");
        ImageView logo = new ImageView(logoImage);
        logo.setFitWidth(450);
        logo.setFitHeight(460);
        logo.setX(350);
        logo.setY(50);
        animation.getChildren().add(logo);
        pane.getChildren().add(animation);

        //逐渐变透明,这里设置成了1不变透明
        Timeline timeline = new Timeline();
        KeyFrame key = new KeyFrame(Duration.millis(5200),
                new KeyValue(logo.opacityProperty(), 1));
        timeline.getKeyFrames().add(key);

        //显示完logo，进入下一步逻辑
        timeline.setOnFinished((ae) -> setUpShow(animation));
        timeline.play();
    }

    //关闭此欢迎页面，显示主页面
    private void setUpShow(Pane animation) {
        //关闭欢迎页面
        pane.getChildren().remove(animation);
        //获取用户是否已经进行设置
        Boolean isSetUp = Boolean.valueOf(ConfigPropertiesUtil.get("is_user_set_up"));
        //没有设置就展开主界面,设置了进入程序执行
        if (Boolean.TRUE.equals(isSetUp)) {
            new Thread(new Task<Void>() {
                @Override
                protected Void call() throws Exception {
                    //后台程序开始运行
                    WallpaperCerebrum.startRun(false);
                    return null;
                }

            }).start();
        } else {
           major();
        }
    }

    private void topMenu(Pane pane) {
        topMenu.setId("topMenu");
        topMenu.setPrefWidth(1145);
        topMenu.setPrefHeight(23);
        topMenu.setLayoutX(180);
        topMenu.setLayoutY(50);
        topMenu.setStyle("-fx-background-color: #f3f4f7;" +
                "-fx-opacity: 0.50;");
        //左上方的菜单
        systemMenu(topMenu);
        //右上方的信号栏及时间
        signalLampMenu(topMenu);

        pane.getChildren().add(topMenu);
        //启动时间更新任务
        dataClockTaskStart();
        //加载后先隐藏，这样做是为了初始化的时候能传递Application对象，用于后面的链接跳转
        topMenu.setVisible(false);
        topMenu.setManaged(false);
    }

    /**
     * mac 右上方时间任务
     */
    public void dataClockTaskStart() {
        Timer timer = new Timer();
        int interval = 1000;
        timer.schedule(new MacTimeTask(), interval, interval);
    }

    /**
     * 下方菜单栏
     *
     * @param pane
     */
    private void bottomMenu(Pane pane) {

        bottomMenuBackground.setPrefWidth(610);
        bottomMenuBackground.setPrefHeight(50);
        bottomMenuBackground.setLayoutX(440);
        bottomMenuBackground.setLayoutY(675);
        bottomMenuBackground.setStyle("-fx-background-color: #e9d7df;" +
                "-fx-opacity: 0.70;" + "-fx-background-radius: 5px;");
        bottomMenuBackground.setId("bottomMenuBackground");

        bottomMenu.setPrefWidth(600);
        bottomMenu.setPrefHeight(50);
        bottomMenu.setLayoutX(460);
        bottomMenu.setLayoutY(675);
        bottomMenu.setSpacing(20);
        bottomMenu.setId("bottomMenu");
        //mac os
        ImageView macos = newBottomMenuButton("/fxml/css/images/mac/mac-os.png");
        bottomMenu.setMargin(macos, new Insets(3));

        //google browser
        ImageView googleBrowser = newBottomMenuButton("/fxml/css/images/mac/google browser.png");
        bottomMenu.setMargin(googleBrowser, new Insets(3));

        //mac browser
        ImageView macBrowser = newBottomMenuButton("/fxml/css/images/mac/mac browser.png");
        bottomMenu.setMargin(macBrowser, new Insets(3));

        //Google Play
        ImageView googlePlay = newBottomMenuButton("/fxml/css/images/mac/Google Play.png");
        bottomMenu.setMargin(googlePlay, new Insets(3));

        //java
        ImageView java = newBottomMenuButton("/fxml/css/images/mac/java.png");
        bottomMenu.setMargin(java, new Insets(3));
        //setup
        ImageView setUp = newBottomMenuButton("/fxml/css/images/mac/set up.png");
        bottomMenu.setMargin(setUp, new Insets(3));

        //music
        ImageView music = newBottomMenuButton("/fxml/css/images/mac/music.png");
        bottomMenu.setMargin(music, new Insets(3));

        //adobePs
        ImageView adobePs = newBottomMenuButton("/fxml/css/images/mac/Adobe Ps.png");
        bottomMenu.setMargin(adobePs, new Insets(3));

        //trash
        ImageView trash = newBottomMenuButton("/fxml/css/images/mac/trash.png");
        bottomMenu.setMargin(trash, new Insets(3));
        trash.setId("trash");

        bottomMenu.getChildren().addAll(macos, googleBrowser, macBrowser,
                googlePlay, java, setUp, music, adobePs, trash);
        pane.getChildren().addAll(bottomMenuBackground, bottomMenu);
    }


    private ImageView newBottomMenuButton(String url) {
        Image image = new Image(url);
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(40);
        imageView.setFitHeight(40);
        return imageView;
    }

    public void setDataClock(String text) {
        Label dataClock = (Label) $("dataClock");
        dataClock.setText(text);
    }

    /**
     * 右上方的信号栏及时间
     *
     * @param topMenu
     */
    private void signalLampMenu(Pane topMenu) {
        HBox hBox = new HBox();
        hBox.setLayoutX(900);
        hBox.setPrefHeight(20);
        hBox.setSpacing(15);

        Button wifi = new Button();
        wifi.setStyle("-fx-shape: 'M512 755.2m-81.024 0a1.266 1.266 0 1 0 162.048 0 1.266 1.266 0 1 0-162.048 0Z M512 512C433.984 512 364.736 548.864 320.192 606.08l42.688 33.216C397.44 594.752 451.264 566.144 512 566.144s114.496 28.608 149.248 73.152l42.56-33.216C659.264 548.864 590.016 512 512 512z M512 187.776c-182.08 0-343.744 86.144-447.552 219.456l43.648 33.92C201.856 320.832 347.712 243.136 512 243.136c164.224 0 310.144 77.696 403.904 198.016l43.712-33.984C855.68 273.856 694.08 187.776 512 187.776z M512 349.888c-130.048 0-245.504 61.44-319.616 156.672l42.624 33.216C299.264 457.28 399.296 403.904 512 403.904s212.672 53.376 277.056 135.872l42.56-33.216C757.504 411.392 642.048 349.888 512 349.888z';-fx-min-height: 15;-fx-background-color: #000000;");
        wifi.setPrefHeight(15);
        wifi.setPrefWidth(15);
        hBox.setMargin(wifi, new Insets(3));

        Button bluetooth = new Button();
        bluetooth.setStyle("-fx-shape: 'm10.998 3v7.041l-3.293-3.293-2e-3 2e-3c-0.35575-0.35595-0.99605-0.99609-0.99605-0.99609l-0.70703 0.70703 4.5449 4.541-4.5449 4.541 0.70703 0.70703s0.64035-0.64009 0.99609-0.99609h2e-3l3.2949-3.293v7.0391h1l4-4-4-4 4-4-4-4zm1.002 1.416 2.5859 2.5859-2.5859 2.5859zm0 8 2.5859 2.5859-2.5859 2.5859z';  -fx-min-height: 15;-fx-background-color: #000000;");
        bluetooth.setPrefHeight(5);
        bluetooth.setPrefWidth(5);
        hBox.setMargin(bluetooth, new Insets(3));

        Button battery = new Button();
        battery.setStyle("-fx-shape: 'M128 682.667h725.333V341.333H128v341.334z m810.667-256v-85.334c0-46.933-38.4-85.333-85.334-85.333H128c-46.933 0-85.333 38.4-85.333 85.333v341.334C42.667 729.6 81.067 768 128 768h725.333c46.934 0 85.334-38.4 85.334-85.333v-85.334c23.466 0 42.666-19.2 42.666-42.666v-85.334c0-23.466-19.2-42.666-42.666-42.666zM896 469.333v213.334c0 23.466-19.2 42.666-42.667 42.666H128c-23.467 0-42.667-19.2-42.667-42.666V341.333c0-23.466 19.2-42.666 42.667-42.666h725.333c23.467 0 42.667 19.2 42.667 42.666v128z';  -fx-min-height: 13; -fx-min-width:25;-fx-background-color: #000000;");
        battery.setPrefHeight(5);
        battery.setPrefWidth(5);
        hBox.setMargin(battery, new Insets(3));

        Label dataClock = new Label();
        dataClock.setId("dataClock");
        hBox.setMargin(dataClock, new Insets(3));

        hBox.getChildren().addAll(wifi, bluetooth, battery, dataClock);
        topMenu.getChildren().addAll(hBox);

    }

    private void systemMenu(Pane topMenu) {
        HBox hBox = new HBox();
        hBox.setLayoutX(20);
        hBox.setPrefHeight(20);
        hBox.setSpacing(15);

        Button macLogo = new Button();
        macLogo.setStyle("-fx-shape: 'M900.427837 723.191558c-20.990015 46.536803-31.064444 67.309877-58.10935 108.440564-37.730247 57.462621-90.927737 128.959859-156.840804 129.594308-58.578023 0.533141-73.606268-38.135476-153.097558-37.665779-79.49129 0.417508-96.078027 38.324787-154.670376 37.793692-65.901811-0.59761-116.320006-65.192661-154.062533-122.615374-105.54359-160.622936-116.571739-349.125794-51.482432-449.329784 46.255394-71.217876 119.22619-112.893984 187.841804-112.893984 69.875301 0 113.795515 38.299205 171.550801 38.299205 56.025902 0 90.163329-38.363673 170.937842-38.363673 61.054419 0 125.725195 33.249199 171.842443 90.698517C723.294911 449.903857 747.837838 665.513019 900.427837 723.191558L900.427837 723.191558z M641.213639 212.301843c29.352456-37.691362 51.636951-90.852013 43.553871-145.216069-47.943846 3.324715-104.011704 33.806899-136.753344 73.552033-29.705496 36.091937-54.236143 89.593349-44.694855 141.624271C555.656202 283.875828 609.805364 252.61798 641.213639 212.301843L641.213639 212.301843z'; -fx-min-height: 20; -fx-background-color: #000000;");
        macLogo.setPrefHeight(5);
        macLogo.setPrefWidth(2);

        Button wallpaper = newSystemMenuButton("壁纸", "wallpaper");

        Button video = newSystemMenuButton("视频", "video");

        Button signOut = newSystemMenuButton("退出", "signOut");
        signOut.setOnMouseClicked(e -> System.exit(0));

        Button setUp = newSystemMenuButton("设置", "setUp");
        setUp.setOnMouseClicked(e -> {
            pane.getChildren().removeAll(brokenHeart);
            brokenHeart.getChildren().clear();
            brokenHeart();
            //开始动画
            repairHeartTime.play();
        });

        Button logo = newSystemMenuButton("日志", "logo");
        logo.setOnMouseClicked(e -> {
            Pane logPane = DownloadLogStage.getInstance().getDoTextAreaLogPane();
            pane.getChildren().add(logPane);
        });

        Button help = newSystemMenuButton("帮助", "help");

        Button minimize = newSystemMenuButton("最小化", "minimize");
        minimize.setPrefWidth(60);
        minimize.setOnMouseClicked(e -> {
            //关闭页面
            this.hide();
            //停止时间更新任务
            MacDateTaskStatusCache.setStatus(false);
        });

        hBox.getChildren().addAll(macLogo, wallpaper, video, setUp, logo, help, signOut, minimize);
        topMenu.getChildren().add(hBox);
    }

    private Button newSystemMenuButton(String name, String id) {
        Button button = new Button(name);
        button.setStyle("-fx-background-color:TRANSPARENT; ");
        button.setPrefWidth(40);
        button.setPrefHeight(20);
        button.setPadding(new Insets(3));
        button.setId(id);

        button.setOnMouseMoved(event ->
                button.setStyle("-fx-font-weight:bold;-fx-text-fill: #000000;"));

        button.setOnMouseExited(e ->
                button.setStyle("-fx-font-weight: lighter;-fx-background-color:TRANSPARENT;"));

        return button;
    }

    private void macWallpaper(Pane pane) {
        //mac边框
        Image macImage = new Image("/fxml/css/images/mac/macbook_0.png");
        ImageView mac = new ImageView(macImage);
        mac.setFitWidth(1500);
        mac.setFitHeight(830);
        //mac的壁纸
        Image macWallpaperImage = new Image(ImagesDataLoaderCache.next());
        ImageView macWallpaper = new ImageView(macWallpaperImage);
        macWallpaper.setFitWidth(1145);
        macWallpaper.setFitHeight(677);
        macWallpaper.setX(180);
        macWallpaper.setY(50);
        pane.getChildren().addAll(mac, macWallpaper);
    }

    //点击按钮打开网站
    public void openSourceURL(Application application) {
        ((Button) $(("help"))).setOnAction(event ->
                application.getHostServices().showDocument("https://gitee.com/missyouch/desserts")
        );
    }

    /**
     * 宇航员
     */
    private void brokenHeart() {
        brokenHeart.setId("brokenHeart");
        brokenHeart.setPrefWidth(1100);
        brokenHeart.setLayoutX(190);
        brokenHeart.setPrefHeight(400);
        brokenHeart.setLayoutY(80);
        //左心
        Button leftHeart = new Button();
        leftHeartButton(HEART_MOVED_COLOR, leftHeart);
        leftHeart.setRotate(-90);
        leftHeart.setId("leftHeart");
        //右心
        Button rightHeart = new Button();
        rightHeartButton(HEART_MOVED_COLOR, rightHeart);
        rightHeart.setRotate(90);
        rightHeart.setId("rightHeart");
        //宇航员 左
        Image astronautLeft = new Image("/fxml/css/images/astronaut/astronaut_left.png");
        ImageView imageView = new ImageView(astronautLeft);
        imageView.setFitWidth(264.6);
        imageView.setFitHeight(220);
        imageView.setX(20);
        imageView.setY(85);
        //宇航员右
        Image astronautRight = new Image("/fxml/css/images/astronaut/astronaut_right.png");
        ImageView imageView1 = new ImageView(astronautRight);
        imageView1.setFitHeight(300);
        imageView1.setFitWidth(178);
        imageView1.setX(810);
        imageView1.setY(35);


        //将绘制的图形加到pane中
        brokenHeart.getChildren().addAll(imageView, imageView1, leftHeart, rightHeart);
        pane.getChildren().add(brokenHeart);
        //绘制动画
        repairHeart(leftHeart, rightHeart, imageView, imageView1);

    }

    //给左心绘制形状
    private void leftHeartButton(String color, Button leftHeart) {
        leftHeart.setLayoutX(200);
        leftHeart.setLayoutY(2);
        leftHeart.setStyle("-fx-shape: 'M -1.453 466.234 L 69.783 287.318 L -32.93 272.409 L 20.083 209.456 L -26.304 212.77 L -6.424 166.384 L -61.091 143.19 L -1.452 68.641 C -104.164 -45.667 -481.878 85.207 -3.11 466.234';-fx-effect: dropshadow(three-pass-box,rgba(0,0,0,0.66),10,0,0,0); -fx-background-color: " + color);
        leftHeart.setPrefHeight(400);
        leftHeart.setPrefWidth(400);

    }

    //给右心绘制形状
    private void rightHeartButton(String color, Button rightHeart) {
        rightHeart.setLayoutX(500);
        rightHeart.setLayoutY(0);
        rightHeart.setStyle("-fx-shape: 'M 1.229 460.337 L 69.783 287.318 L -32.93 272.409 L 20.083 209.456 L -26.304 212.77 L -6.424 166.384 L -61.091 143.19 L -1.452 68.641 c 189.719 -124.72 433.028 67.279 2.686 393.347';-fx-effect: dropshadow(three-pass-box,rgba(0,0,0,0.66),10,0,0,0);-fx-background-color: " + color);
        rightHeart.setPrefHeight(400);
        rightHeart.setPrefWidth(400);
    }

    private void repairHeart(Button leftHeart,
                             Button rightHeart,
                             ImageView astronautLeft,
                             ImageView astronautRight) {


        //---------------------------leftHeart--------------------------
        //倾斜90度
        KeyValue kv1 = new KeyValue(leftHeart.rotateProperty(), -90, Interpolator.EASE_BOTH);
        //正90度
        KeyValue kv2 = new KeyValue(leftHeart.rotateProperty(), 0, Interpolator.EASE_BOTH);
        //--------------------- rightHeart ------------------------------
        //倾斜90度
        KeyValue kv3 = new KeyValue(rightHeart.rotateProperty(), 90, Interpolator.EASE_BOTH);
        //正90度
        KeyValue kv4 = new KeyValue(rightHeart.rotateProperty(), 0, Interpolator.EASE_BOTH);

        //倾斜保持1秒
        KeyFrame kf = new KeyFrame(Duration.seconds(1), kv1, kv3);
        //8秒内旋转到中度
        KeyFrame kf1 = new KeyFrame(Duration.seconds(8), kv2, kv4);

        //--------------------astronautLeft 平移动画-----------------------------------
        //x保持不变
        KeyValue kv5 = new KeyValue(astronautLeft.translateXProperty(), 0);
        //y保持不变
        KeyValue kv6 = new KeyValue(astronautLeft.translateYProperty(), 0);
        //移动x
        KeyValue kv7 = new KeyValue(astronautLeft.translateXProperty(), 120, Interpolator.EASE_BOTH);
        //移动y
        KeyValue kv8 = new KeyValue(astronautLeft.translateYProperty(), -20, Interpolator.EASE_BOTH);

        //--------------------astronautRight 平移动画-----------------------------------
        KeyValue kv9 = new KeyValue(astronautRight.translateXProperty(), 0);
        KeyValue kv10 = new KeyValue(astronautRight.translateYProperty(), 0);
        KeyValue kv11 = new KeyValue(astronautRight.translateXProperty(), -95, Interpolator.EASE_BOTH);
        KeyValue kv12 = new KeyValue(astronautRight.translateYProperty(), -10, Interpolator.EASE_BOTH);

        //astronautLeft保持1秒不动
        KeyFrame kf2 = new KeyFrame(Duration.seconds(1), kv5, kv6);
        //astronautLeft8秒内移动到目标位置
        KeyFrame kf3 = new KeyFrame(Duration.seconds(7.6), kv7, kv8);

        //astronautRight 保持1秒不动
        KeyFrame kf4 = new KeyFrame(Duration.seconds(1), kv9, kv10);
        //astronautRight 8秒内移动到目标位置
        KeyFrame kf5 = new KeyFrame(Duration.seconds(8), kv11, kv12);

        repairHeartTime.getKeyFrames().addAll(kf, kf1, kf2, kf3, kf4, kf5);

        //逐渐变透明
        Timeline opacity = new Timeline();
        //astronautLeft 2.5秒消失
        KeyFrame leftOpacity = new KeyFrame(Duration.millis(1500), new KeyValue(astronautLeft.opacityProperty(), 0));
        KeyFrame rightOpacity = new KeyFrame(Duration.millis(1500), new KeyValue(astronautRight.opacityProperty(), 0));

        opacity.getKeyFrames().addAll(leftOpacity, rightOpacity);

        //完成移动后逐渐透明
        repairHeartTime.setOnFinished(ae -> opacity.play());
        opacity.setOnFinished(ae -> {
            try {
                typeChoice();
            } catch (IOException e) {
                e.printStackTrace();
            }
            initMouseCusor(leftHeart, rightHeart);
            brokenHeartClicked();
        });

    }

    /**
     * video or picture wallpaper type choice node
     */
    private void typeChoice() throws IOException {
        ImageView picture = new ImageView(new Image("/fxml/css/images/type/picture.png"));
        picture.setFitWidth(60);
        picture.setFitHeight(60);
        picture.setX(415);
        picture.setY(115);
        picture.setId("pictureImages");

        Label pictureText = new Label();
        pictureText.setText("图片壁纸");
        pictureText.setLayoutX(415);
        pictureText.setLayoutY(185);
        pictureText.setFont(Font.loadFont(this.getClass().getResource("/fxml/font/FZYongKTJF_Da.TTF").openStream(), 18));
        pictureText.setId("pictureText");

        ImageView video = new ImageView(new Image("/fxml/css/images/type/video.png"));
        video.setFitHeight(60);
        video.setFitWidth(104);
        video.setX(585);
        video.setY(100);
        video.setId("videoImage");

        Label videoText = new Label();
        videoText.setText("视频壁纸");
        videoText.setLayoutX(598);
        videoText.setLayoutY(150);
        videoText.setFont(Font.loadFont(this.getClass().getResource("/fxml/font/FZYongKTJF_Da.TTF").openStream(), 20));
        videoText.setTextFill(Paint.valueOf("#2177b8"));
        videoText.setId("videoText");

        brokenHeart.getChildren().addAll(picture, pictureText, video, videoText);
    }

    /**
     * Broken Heart Clicked
     */
    private void brokenHeartClicked() {
        Button rightHeart = ((Button) $("rightHeart"));
        Button leftHeart = ((Button) $("leftHeart"));

        rightHeart.setOnMouseClicked(e -> {
            //改变底部菜单栏
            trashEnlarge();
            //禁用heart按钮但是不使用系统默认的透明度
            rightHeart.setDisable(true);
            rightHeart.setOpacity(0.75);
            //将点击的相反的heart也禁用掉，透明度不改变
            leftHeart.setDisable(true);
            leftHeart.setOpacity(1);
            //开启点击的相反的heart掉落的动画
            heartExitAnimation(leftHeart,rightHeart);
        });

        leftHeart.setOnMouseClicked(e -> {
            trashEnlarge();
            leftHeart.setDisable(true);
            leftHeart.setOpacity(0.75);
            rightHeart.setDisable(true);
            rightHeart.setOpacity(1);
            heartExitAnimation(rightHeart,leftHeart);
        });
    }

    /**
     * Heart Exit Animation
     *
     * @param mainButton 须操作的button
     * @param minorButton 用户选中的button
     */
    private void heartExitAnimation(Button mainButton,Button minorButton) {
        String id = minorButton.getId();
        int rotate =  -30;
        int translateX = 140;
        int translateY = 310;
        if (id.equals("leftHeart")){
            rotate = 30;
            translateX = -100;
            translateY = 310;
        }
        Timeline timeline = new Timeline();
        //先旋转30度
        KeyFrame kf1 = new KeyFrame(Duration.millis(30),new KeyValue(mainButton.rotateProperty(), rotate, Interpolator.EASE_BOTH));
        timeline.getKeyFrames().add(kf1);

        //平移动画
        KeyValue kv2 = new KeyValue(mainButton.translateXProperty(), translateX, Interpolator.EASE_BOTH);
        KeyValue kv3 = new KeyValue(mainButton.translateYProperty(), translateY, Interpolator.EASE_BOTH);
        KeyFrame kf2 = new KeyFrame(Duration.seconds(2), kv2, kv3);
        //缩放动画
        KeyValue kv4 = new KeyValue(mainButton.scaleXProperty(), 0.25, Interpolator.EASE_BOTH);
        KeyValue kv5 = new KeyValue(mainButton.scaleYProperty(), 0.25, Interpolator.EASE_BOTH);
        KeyFrame kf3 = new KeyFrame(Duration.seconds(2), kv4, kv5);
        //旋转动画
        //先保持1秒
        KeyFrame kf4 = new KeyFrame(Duration.seconds(1), new KeyValue(minorButton.rotateProperty(), 0, Interpolator.EASE_BOTH));
        //随后的一秒内旋转n圈
        KeyValue kv7 = new KeyValue(minorButton.rotateProperty(), 360, Interpolator.EASE_BOTH);
        KeyFrame kf5 = new KeyFrame(Duration.seconds(3), kv7);
        KeyFrame kf6 = new KeyFrame(Duration.millis(2500), new KeyValue(minorButton.opacityProperty(), 0));


        Timeline timeline1 = new Timeline();
        timeline1.getKeyFrames().addAll(kf2, kf3,kf4,kf5,kf6);

        timeline.play();
        timeline.setOnFinished(t -> {
            //将这几个节点移除
            removeNode(brokenHeart,"pictureImages","pictureText","videoImage","videoText");
            //开始放映移动及缩放动画
            timeline1.play();
        });
        timeline1.setOnFinished(t -> {
            try {

                if (id.equals("rightHeart")){
                    setUpChoice = VideoSetUpStage.getInstance().getSetUpPane();
                }else {
                    setUpChoice = SetUpChoiceStage.getInstance().getPane();
                }


                pane.getChildren().add(setUpChoice);
            } catch (IOException e) {
                e.printStackTrace();
            }
            //把两瓣心，回收站,无用的布局都抬走
            removeNode(brokenHeart,"leftHeart","rightHeart");
            bottomMenu.getChildren().clear();
            pane.getChildren().removeAll(bottomMenu,bottomMenuBackground,brokenHeart);
            removeNode(pane,"trash2");
            bottomMenu(pane);

        });

    }
    /**
     * 从指定的Pane中删除指定id节点
     * @param node
     * @param ids
     */
    private void removeNode(Pane node,String... ids){
        for (int i = 0; i <ids.length ; i++) {
            super.removeNode(node,ids[i]);
        }
    }
    /**
     * 底部菜单栏 trash移动及放大
     */
    private void trashEnlarge() {
        //trash
        ImageView imageView = new ImageView(new Image("/fxml/css/images/mac/trash2.png"));
        imageView.setFitHeight(150);
        imageView.setFitWidth(150);
        imageView.setX(680);
        imageView.setY(570);
        imageView.setId("trash2");

        //加载两个透明占位图片
        ImageView transparent = new ImageView(new Image("/fxml/css/images/mac/transparent.png"));
        transparent.setFitHeight(40);
        transparent.setFitWidth(40);
        ImageView transparent1 = new ImageView(new Image("/fxml/css/images/mac/transparent.png"));
        transparent1.setFitHeight(40);
        transparent1.setFitWidth(40);

        ObservableList<Node> workingCollection = FXCollections.observableArrayList(bottomMenu.getChildren());
        workingCollection.add(4, transparent);
        workingCollection.add(5, transparent1);
        workingCollection.remove(workingCollection.size() - 1);

        //更新底部菜单栏的长度及位置
        bottomMenuBackground.setPrefWidth(650);
        bottomMenuBackground.setPrefHeight(50);
        bottomMenuBackground.setLayoutX(430);

        bottomMenu.setPrefWidth(640);
        bottomMenu.setPrefHeight(50);
        bottomMenu.setLayoutX(440);

        bottomMenu.getChildren().setAll(workingCollection);

        //改变层级顺序，避免遮挡
        ObservableList<Node> paneNode = FXCollections.observableArrayList(pane.getChildren());
        paneNode.add(5, imageView);
        pane.getChildren().setAll(paneNode);
    }

    /**
     * 移入移出事件
     *
     * @param leftHeart
     * @param rightHeart
     */
    private void initMouseCusor(Button leftHeart, Button rightHeart) {
        leftHeart.setOnMouseMoved(event ->
                leftHeartButton(HEART_EXIT_COLOR, leftHeart)
        );

        leftHeart.setOnMouseExited(e ->
                leftHeartButton(HEART_MOVED_COLOR, leftHeart));

        rightHeart.setOnMouseMoved(event ->
                rightHeartButton(HEART_EXIT_COLOR, rightHeart));

        rightHeart.setOnMouseExited(e ->
                rightHeartButton(HEART_MOVED_COLOR, rightHeart));
    }

    /**
     * 选择界面元素
     *
     * @param id
     * @return
     */
    @Override
    public Object $(String id) {
        return pane.lookup("#" + id);
    }

    public Object getPane(){
        return pane;
    }

    public void removeSetUpMenu(){
        removeMenu(setUpChoice);
    }

    public void removeMenu(Pane menuPane){
       pane.getChildren().remove(menuPane);
    }
}